package model;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import managerService.ManagerSystem;

public class Project {
	
	private String name;
	private String description;
	private List<Building> buildings;
	private int id;
	private Type type;

	public Project() {
		buildings = new ArrayList<Building>();
		this.id = Singleton.getIdBat();
	}
	
	public void addBuilding(Building build){
		buildings.add(build);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public List<Building> getBuildings() {
		return buildings;
	}

	public void setBuildings(List<Building> buildings) {
		this.buildings = buildings;
	}
	
	
	private int getId() {
		return this.id;
	}
	
	public void setType(Type type) {
		this.type = type;
	}
	
	public Type getType() {
		return type;
	}
	
	public String toXML(){
		StringBuilder builder = new StringBuilder();
		builder.append("<project>\n\t<name>");
		builder.append(this.getName());
		builder.append("</name>\n");
		builder.append("\t<description>");
		builder.append(this.getDescription());
		builder.append("</description>\n");
		builder.append("\t<type>\n");
		builder.append("\t\t<name>");
		builder.append(this.type.getName());
		builder.append("</name>\n");
		builder.append("\t\t<id>");
		builder.append(this.type.getId());
		builder.append("</id>\n");
		builder.append("\t</type>\n");
		builder.append("\t<id>");
		builder.append(this.getId());
		builder.append("</id>\n");
		
		for(Building b : buildings){
			builder.append(b.toXML());
		}
		builder.append("</project>");
		return builder.toString();
	}
	
	public void toFile(){
		Singleton.toFile(this.toXML(),
				ManagerSystem.getService().getProjectXMLPath() + File.separator + this.name + ".xml");
	}
	
}
